/* R. J. Cano, Aug 07 2014
 * 
 * Example: Dump of an execution (Linux/Unix).

sh-4.2$ gp -f -s 1024000000 AdditionalInfoA242046.txt # The stack size choice shown here is customary.

                                GP/PARI CALCULATOR Version 2.7.1 (released)
                         i686 running linux (ix86/GMP-5.1.3 kernel) 32-bit version
                              compiled: Jul 26 2014, gcc version 4.8.2 (GCC) 
                                          threading engine: single
                               (readline v5.2 enabled, extended help enabled)

                                   Copyright (C) 2000-2014 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY 
WHATSOEVER.

Type ? for help, \q to quit.
Type ?12 for how to get moral (and possibly technical) support.

parisize = 1024000000, primelimit = 500000
? ? 0 \\ Routines defined only by AdditionalInfoA242046.txt;

a      aStr   ap     av     fixMe  letter 

?

*/

demo()={
  
\\ -------------- 8< Copy and paste on such GP session ------------------- [Begin]

terms=2500; \\ The reader is encouraged here for repeating this test with higher values.

sample002=vector(terms,j,aStr(j,2));  \\ Binary
sample003=vector(terms,j,aStr(j,3));  \\ Base 3
sample004=vector(terms,j,aStr(j,4));  \\ Base 4
sample008=vector(terms,j,aStr(j,8));  \\ Octal 
sampleDef=vector(terms,j,aStr(j));    \\ By default: Decimal or Base10
sample012=vector(terms,j,aStr(j,12)); \\ Duodecimal
sample016=vector(terms,j,aStr(j,16)); \\ Hexadecimal

\\ From Base 4 onward, terms with the same offset must have identical lengths in digits/letters.
\\ sampleDef is taken as reference ("cmp" stands for "comparison"). 

\\ It is expected that this comparison fails for Binary: Since there

\\ are less basic elements (less than 4, just 2, "0" and "1").
\\ (For Base 3 apparently it should fail, but observe there that One of the basic elements
\\ actually is duplicated)

\\ This initial obvious comparison proves that the test works fine.

cmpDef=(#sampleDef==#sampleDef)*prod(j=1,#sampleDef,#sampleDef[j]==#sampleDef[j]);

if(cmpDef,print("\n\nThe proposed comparison makes sense and works."),print("\n\nHey!: Something is wrong here.");quit());

\\ The expected fail.

cmp002=(#sampleDef==#sample002)*prod(j=1,#sampleDef,#sampleDef[j]==#sample002[j]);

\\ The empirical* verification of the observed and PRESUMABLY GENERAL properties.
\\ (*Note: Not exhaustive at all)

cmp003=(#sampleDef==#sample003)*prod(j=1,#sampleDef,#sampleDef[j]==#sample003[j]);
cmp004=(#sampleDef==#sample004)*prod(j=1,#sampleDef,#sampleDef[j]==#sample004[j]);
cmp008=(#sampleDef==#sample008)*prod(j=1,#sampleDef,#sampleDef[j]==#sample008[j]);
cmp012=(#sampleDef==#sample012)*prod(j=1,#sampleDef,#sampleDef[j]==#sample012[j]);
cmp016=(#sampleDef==#sample016)*prod(j=1,#sampleDef,#sampleDef[j]==#sample016[j]);

/* By having in account the leading zeros problem with x=2 or binary */

sampleDefAltered=vector(terms,j,leadingChrDel("8",sampleDef[j]));
cmp002again=(#sampleDefAltered==#sample002)*prod(j=1,#sampleDefAltered,#sampleDefAltered[j]==#sample002[j]);

answer=(!cmp002)*cmp003*cmp004*cmp008*cmp012*cmp016*cmp002again;

print("\n\n\n\n...Done!.\n\nConclusion. Are we right relative to our initial & informal description for this seq.?: "if(answer,"Yes.","Nope!, Oops."));

\\ -------------- 8< Copy and paste on such GP session ------------------- [End]

}

/* After the execution is completed for the pasted block, the result must be:
-------------------------------------------------------------------------------- 


The proposed comparison makes sense and works.



...Done!.

Conclusion. Are we right relative to our initial & informal description for this seq.?: Yes.

  
 -----------------------------------------
      ------------------------------
          --------------------
             --------------
                 -----
                   -
                   
Deja Vu. Another alternative: Simply loading this file as script with GP */

ap(n,x)={my(s);forprime(p=1,n,s+=x^p);s}
a(n,x=10)={abs((x^(n+1)-1)/(x-1)-2*ap(n,x)-1)}
av(n,x,y=x)=digits(a(n,x),y);
fixMe(i,B)=if(i>=B,B-1,i);
letter(i)=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"][fixMe(i,36)+1];
aStr(n,x=10,y=x)={my(s="",w=av(n,x,y));for(j=1,#w,s=Str(s,letter(w[j])));s}
/* Deletes leading character given by str1[1], str1[2], ... from  str2 (recursive version) */
leadingChrDel(str1,str2,index=1)={my(ans="",V0=Vecsmall("0"),V1=Vecsmall(str1),V2=Vecsmall(str2),j);while(V2[j++]==V1[index],);while(j<=#str2,ans=Str(ans,letter(V2[j]-V0[1]));j++);if(index==#str1,ans,leadingChrDel(str1,ans,index+1))};

demo();

/* The End */